package com.etime.shycourse.services.account.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.etime.shycourse.dao.SettlementMapper;
import com.etime.shycourse.dto.SettlementDto;
import com.etime.shycourse.services.account.interfaces.AccountMyOrgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Author liukang
 * @Date 2022/7/26 14:27
 */
@Service
public class AccountMyOrgServiceImpl implements AccountMyOrgService {
@Autowired
    SettlementMapper settlementMapper;
    @Override
    public Page<SettlementDto> getOrgSettlements(long pagenum, long pagesize, int settlementpay,int orgid) {
        Page<SettlementDto> settlementDtoPage = new Page<>(pagenum, pagesize);
        QueryWrapper<SettlementDto> settlementDtoQueryWrapper = new QueryWrapper<>();
        settlementDtoQueryWrapper.eq("settlementpay",settlementpay);
        settlementDtoQueryWrapper.eq("org.orgid",orgid);
        Page<SettlementDto> orgSettlements = settlementMapper.getOrgSettlements(settlementDtoPage, settlementDtoQueryWrapper);
        return orgSettlements;
    }

    @Override
    public Page<SettlementDto> getOrgSettlementDetails(long pagenum, long pagesize, int settlementpay, int orgid) {

        Page<SettlementDto> settlementDtoPage = new Page<>(pagenum, pagesize);
        QueryWrapper<SettlementDto> settlementDtoQueryWrapper = new QueryWrapper<>();
        settlementDtoQueryWrapper.eq("settlementpay",settlementpay);
        settlementDtoQueryWrapper.isNotNull("org.orgid");
        settlementDtoQueryWrapper.eq("s.settlementuserid",orgid);
        Page<SettlementDto> orgSettlementDetails = settlementMapper.getOrgSettlementDetails(settlementDtoPage, settlementDtoQueryWrapper);
        return orgSettlementDetails;
    }

    @Override
    public Page<Date> findDateList(long pagenum, long pagesize, int settlementpay, Integer orgid) {
        if(orgid>0){
            return null;
        }
        Page<Date> datePage = new Page<>(pagenum, pagesize);
        QueryWrapper<Date> dateQueryWrapper = new QueryWrapper<>();
        dateQueryWrapper.eq("settlementpay",settlementpay);
        dateQueryWrapper.eq("settlementuserid",orgid);
        dateQueryWrapper.isNotNull("org.orgid ");
        return settlementMapper.orgFindDateList(datePage,dateQueryWrapper);
    }

    @Override
    public List<SettlementDto> getSettlementByDate(int settlementpay, String settlementtime, int orgid) {
        System.out.println("settlementtime"+settlementtime);
        System.out.println("settlementtime"+settlementpay);
        QueryWrapper<SettlementDto> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("settlementpay",settlementpay);
        queryWrapper.eq("settlementtime",settlementtime);
        queryWrapper.eq("settlementuserid",orgid);
        queryWrapper.isNotNull("org.orgid");
        return settlementMapper.orgGetSettlementByDate(queryWrapper);
    }
}
